package com.qiaofang.collectmanage.dao.impl;
import com.qiaofang.collectmanage.dao.domain.CollectQuality;
import com.qiaofang.collectmanage.dao.mapper.CollectQualityMapper;
import com.qiaofang.collectmanage.dao.CollectQualityDao;
import com.qiaofang.collectmanage.stub.constants.DeletedEnum;
import com.qiaofang.common.datasource.tkmapper.InsertListSelectiveMapperUtil;
import com.qiaofang.common.model.page.PageDTO;
import com.qiaofang.common.page.PageUtil;
import com.qiaofang.collectmanage.stub.bean.SearchCollectQualityDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;
import tk.mybatis.mapper.entity.Example;
import org.apache.ibatis.session.RowBounds; 
/**
* Created by generator on 2018-8-1 20:37:55
*/
@Repository("collectQualityDao")
public class CollectQualityDaoImpl implements CollectQualityDao{

    @Autowired
    private CollectQualityMapper qualityMapper;

    @Override
    public CollectQuality  getCollectQualityByUuid(String uuid){
       CollectQuality  quality = new CollectQuality();
       quality.setUuid(uuid);
        return qualityMapper.selectOne(quality);
   }


    @Override
    public CollectQuality getCollectQualityByQuality(CollectQuality quality){
        return qualityMapper.selectOne(quality);
    }

    @Override
    public int saveCollectQuality(CollectQuality quality) {
         return qualityMapper.insertSelective(quality);
    }

    @Override
    public int  updateCollectQuality (CollectQuality quality) {
        Example ex = new Example(CollectQuality.class);
         ex.createCriteria()
         .andIsNotNull("uuid")
         .andEqualTo("uuid",quality.getUuid());
        return  qualityMapper.updateByExampleSelective(quality,ex);
    }

    @Override
    public int removeCollectQualityByUuid (String uuid){
        Example ex = new Example(CollectQuality.class);
        ex.createCriteria().andEqualTo("uuid",uuid);
        CollectQuality quality = new  CollectQuality();
        quality.setDeleted(DeletedEnum.NO.getValue());
        return  qualityMapper.updateByExampleSelective(quality,ex);
    }


    @Override
    public List<CollectQuality> listCollectQuality(CollectQuality quality){
          if(quality == null){
              quality  = new CollectQuality();
          }
         quality.setDeleted(DeletedEnum.NO.getValue());
          return qualityMapper.select(quality);
    }


        @Override
        public List<CollectQuality> listCollectQualityByUuids(List<String> uuidList){
           Example ex = new Example(CollectQuality.class);
           ex.createCriteria().andIn("uuid",uuidList);
           return qualityMapper.selectByExample(ex);
        }

    @Override
    public  Long countCollectQuality(CollectQuality quality){
        if(quality == null){
          quality  = new CollectQuality();
        }
         quality.setDeleted(DeletedEnum.NO.getValue());
         return Long.valueOf(qualityMapper.selectCount(quality));
    }

    @Override
    public List<CollectQuality> searchCollectQualityBySimpleAttr(CollectQuality quality,RowBounds rb){
        if(quality == null){
           quality  = new CollectQuality();
        }
         quality.setDeleted(DeletedEnum.NO.getValue());
         return qualityMapper.selectByRowBounds(quality,rb);
    }

    @Override
    public List<CollectQuality> searchCollectQualityByPermission(SearchCollectQualityDTO dto,PageDTO page){
        Example example = new Example(CollectQuality.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("deleted", 0);
        return qualityMapper.selectByExampleAndRowBounds(example,PageUtil.getRowBounds(page));
    }

    @Override
    public Long countCollectQualityByPermission(SearchCollectQualityDTO dto){
        Example example = new Example(CollectQuality.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("deleted", 0);
       return Long.valueOf(qualityMapper.selectCountByExample(example));
    }

    @Override
    public int saveCollectQualityBatch(List<CollectQuality> collectQualityList) {
        return InsertListSelectiveMapperUtil.insertListSelective(qualityMapper, collectQualityList);
    }
}
